import express from 'express';
import cors from 'cors';
import adminRouter from '../admin/admin.router';
import authRouter from '../auth/auth.router';
import goldPostsRouter from '../goldPosts/goldPosts.router';
import goldShopRouter from '../goldShop/goldShop.router';
import jobsRouter from '../jobs/jobs.router';
import houseRouter from '../house/house.router';
import oilRouter from '../oil/oil.router';
import carRouter from '../car/car.router';
import secondHandRouter from '../secondHand/secondHand.router';
import pickUpRouter from '../pickUp/pickUp.router';
import tutorRouter from '../tutor/tutor.router';
import throwRouter from '../throw/throw.router';
import repairShopRouter from '../repairShop/repairShop.router';
import deliveryRouter from '../delivery/delivery.router';
import rechargeRouter from '../recharge/recharge.router';
import complaintRouter from '../complaint/complaint.router';
import favoritesRouter from '../favorites/favorites.router';
import onAppRouter from '../onApp/onApp.router';
import swiperRouter from '../swiper/swiper.router';
import commentRouter from '../comment/comment.router';
import newMovieRouter from '../newMovie/newMovie.router';
import videoPlayRouter from '../videoPlay/videoPlay.router';
import actorRouter from '../actor/actor.router';
import serviceRouter from '../service/service.router';
import shopRouter from '../shop/shop.router';
import goodsRouter from '../goods/goods.router';
import marketPriceRouter from '../marketPrice/marketPrice.router';
import infoFieldRouter from '../infoField/infoField.router';
import userRouter from '../user/user.router';
import advertiseRouter from '../advertise/advertise.router';
import aboutRouter from '../about/about.router';
import notificationRouter from '../notification/notification.router';
import categoryRouter from '../category/category.router';
import orderRouter from '../order/order.router';
import videosRouter from '../videos/videos.router';
import userAuthRouter from '../user_auth/user_auth.router';
import mainPageRouter from '../mainPage/mainPage.router';
import tokenRouter from '../tokenCookie/tokenCookie.router';
import indexRouter from '../index/index.router';
import generatePictureRouter from '../generatePicture/generatePicture.router';
import kitapRouter from '../kitap/kitap.router';
import signRouter from '../sign/sign.router';
import previewRouter from '../preview/preview.router';
import bookRouter from '../book/book.router';
import { defaultErrorHandler } from './app.middleware';

/**
 * 创建应用
 */
const app = express();

/**
 * 跨域资源共享
 */
app.use(
  cors({
    origin: '*',
    exposedHeaders: 'X-Total-Count',
  }),
);

/**
 * 处理 XML
 */
app.use(express.text({ type: 'text/xml' }));

/**
 * 处理 JSON
 */
app.use(express.json());

/**
 * 路由
 */
app.use(
    adminRouter,
    authRouter,
    goldPostsRouter,
    goldShopRouter,
    jobsRouter,
    houseRouter,
    oilRouter,
    carRouter,
    secondHandRouter,
    pickUpRouter,
    throwRouter,
    tutorRouter,
    repairShopRouter,
    deliveryRouter,
    rechargeRouter,
    complaintRouter,
    favoritesRouter,
    onAppRouter,
    swiperRouter,
    commentRouter,
    newMovieRouter,
    videoPlayRouter,
    actorRouter,
    serviceRouter,
    shopRouter,
    marketPriceRouter,
    goodsRouter,
    infoFieldRouter,
    userRouter,
    advertiseRouter,
    aboutRouter,
    notificationRouter,
    categoryRouter,
    orderRouter,
    videosRouter,
    userAuthRouter,
    mainPageRouter,
    tokenRouter,
    indexRouter,
    generatePictureRouter,
    kitapRouter,
    signRouter,
    previewRouter,
    bookRouter,
  );

/**
 * 异常处理器
 */
app.use( defaultErrorHandler );
app.use(express.static('uploads'));

/**
 * 导出
 */
export default app;
